import cv2
img = cv2.imread('Lena.jpg')

if img is None:
    print("Error: Could not read the image.")
else:   
    # Display the image in a window
    cv2.imshow('Lena', img)

    # Wait for a key press and close the window
    cv2.waitKey(0)
    cv2.destroyAllWindows()

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    # 显示灰度图
    cv2.imshow('Lena Gray', gray)

    # 等待按键并关闭所有窗口
    cv2.waitKey(0) 
    cv2.destroyAllWindows()

    # 灰度图转为热力图显示
    heatmap = cv2.applyColorMap(gray, cv2.COLORMAP_JET)
    # 显示热力图
    cv2.imshow('Lena Heatmap', heatmap)
    # 等待按键并关闭所有窗口
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    
    # 调整亮度和对比度
    alpha = 1.2
    beta = 30
    adjusted = cv2.convertScaleAbs(img, alpha=alpha, beta=beta)
    # 显示调整后的图像  
    cv2.imshow('Adjusted', adjusted)
    # 等待按键并关闭所有窗口     
    cv2.waitKey(0)
    cv2.destroyAllWindows()
